package com.hxd.otc.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.hxd.otc.R;


/**
 * 作  者 :  胡庆岭
 * 时  间 :  2018/7/13 10:54
 * 描  述 :  ${广告说明Dialog}
 */
public class PublishAddExplainDialog extends Dialog {

    private View mCloseView;

    public PublishAddExplainDialog(@NonNull Context context) {
        this(context, R.style.DialogStyle);
    }

    public PublishAddExplainDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        init();

    }

    private void init() {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.weight_publish_add_dialog_view);
        initView();
        initEvent();
        initWindows();
    }

    private void initView() {
        mCloseView = findViewById(R.id.close_iv);
    }

    private void initEvent() {
        mCloseView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    private void initWindows() {
        setCanceledOnTouchOutside(true);
        Window window = getWindow();
        if (window != null) {
            DisplayMetrics dm = new DisplayMetrics();
            window.getWindowManager().getDefaultDisplay().getMetrics(dm);
            WindowManager.LayoutParams windowAttributes = window.getAttributes();
            windowAttributes.width = WindowManager.LayoutParams.MATCH_PARENT;
            windowAttributes.height = WindowManager.LayoutParams.WRAP_CONTENT;
            windowAttributes.gravity = Gravity.BOTTOM;
            window.setAttributes(windowAttributes);
        }
    }
}
